<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
      }
      .weibo {
        width: 375px;
        height: 667px;
        border: 1px solid #000;
        position: relative;
      }

      header {
        width: 100%;
        height: 60px;
        border-bottom: 1px solid #000;
        text-align: center;
        line-height: 60px;
      }

      footer {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 60px;
        border-top: 1px solid #000;
        display: flex;
        justify-content: space-around;
        align-items: center;
      }

      .item {
        width: 345px;
        margin: 15px;
        border: 1px solid #000;
        height: 150px;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <wei-bo></wei-bo>
    </div>

    <script src="./Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      // 创建头部组件
      const WeiBoHeader = {
        template: `
          <header>微博首页</header>
        `,
      };

      // 创建按钮组件
      const WbButton = {
        props: ["font"],
        template: `
          <button>{{ font }}</button>
        `,
      };

      // 创建列表item组件
      const ContentItem = {
        props: ["item"],
        data() {
          return {
            size: 20,
          };
        },
        template: `
          <div class="item">
            <h3>{{ item.title }}</h3>
            <p>{{ item.content }}</p>
            <wb-button font="点赞"></wb-button>
            <button @click="minus">-</button>
          </div>
        `,
        methods: {
          minus() {
            this.size--;
            this.$emit("minus", this.size);
          },
        },
        components: {
          WbButton,
        },
      };

      // 创建内容组件
      const WeiBoContent = {
        data() {
          return {
            size: 20,
            list: [
              {
                title: "喜迎二十大｜宁夏：让塞上江南更美好",
                content:
                  "金秋好时节，丰收正当时。宁夏回族自治区银川市贺兰县稻渔空间乡村生态观光园里，以大地为纸",
              },
              {
                title: "载人航天三十年，筑梦太空新高度",
                content:
                  "这是曾经只存在于科幻想象的画面，如今中国人已将它变为现实",
              },
              {
                title: "摩洛哥小伙亚瑟的“小确幸”",
                content:
                  "24岁的亚瑟是一个热爱功夫的摩洛哥小伙，如今已经在洛阳生活了三年。",
              },
            ],
          };
        },
        template: `
          <main :style="{'font-size': size + 'px'}">
            <content-item 
              v-for="(item, index) in list" 
              :key="index" 
              :item="item"
              @minus="getSize"
            ></content-item>
          </main>
        `,
        components: {
          ContentItem,
        },
        methods: {
          getSize(size) {
            // console.log("getSize");
            this.size = size;
          },
        },
      };

      // 创建form组件
      const WeiBoForm = {
        template: `
          <footer>
            <input type="text" />
            <wb-button font="发布"></wb-button>
          </footer>
        `,
        components: {
          WbButton,
        },
      };

      // 创建微博的组件
      const WeiBo = {
        template: `
          <div class="weibo">
            <wei-bo-header></wei-bo-header>
            <wei-bo-content></wei-bo-content>
            <wei-bo-form></wei-bo-form>
          </div>
        `,
        components: {
          WeiBoHeader,
          WeiBoContent,
          WeiBoForm,
        },
      };

      createApp({
        data() {
          return {};
        },
        // 注册组件
        components: {
          WeiBo,
        },
      }).mount("#app");
    </script>
  </body>
</html>
